Skip to content

Handle "Escape" key for TextInput #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 24, 2022
Merged

Conversation

Saadnajmi
Copy link
Collaborator

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

TextInput did not properly handle the "Escape" Key. This is probably because iOS doesn't have an escape key, so we have to special case it for macOS. Normally, onKeyPress is called for each key that changes the text inside a TextInput. There are a few exceptions: Enter, Delete, Backspace. Those keys have special keybindings in Appkit, and are handled in a different codepath as described here -> onmyway133/blog#635 .

My change adds "Escape" as one of these special cased keys. Pressing Escape will end editing, remove focus from the text field, and send a KeyPress event. This seemed like the most reasonable defualt.

Changelog

[macOS] [Fixed] - Handle Escape key for TextInput

Test Plan

I put some console.logs() inside the RNTesterPage for TextInput to verify Escape was being hit inside onKeyPress.

@Saadnajmi Saadnajmi requested a review from a team as a code owner February 23, 2022 23:02
@Saadnajmi Saadnajmi merged commit d7a11ea into microsoft:main Feb 24, 2022
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Feb 24, 2022
* wip

* onKeyPress works

* Minor cleanup

* spaces not tabs
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Feb 24, 2022
* wip

* onKeyPress works

* Minor cleanup

* spaces not tabs
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Feb 24, 2022
* wip

* onKeyPress works

* Minor cleanup

* spaces not tabs
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Feb 24, 2022
* wip

* onKeyPress works

* Minor cleanup

* spaces not tabs
@Saadnajmi Saadnajmi deleted the escape branch February 24, 2022 18:34
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Feb 24, 2022
Saadnajmi added a commit to Saadnajmi/react-native-macos that referenced this pull request Feb 24, 2022
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Aug 8, 2022
This extends the ability to intercept `keyDown` and `keyUp` events to `TextInput`.
We need this for the ability to insert newlines when holding shift in chat, along with support arrow up/down from the search input.

Will the change here cause a conflict with microsoft#1044 ?
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Aug 10, 2022
This extends the ability to intercept `keyDown` and `keyUp` events to `TextInput`.
We need this for the ability to insert newlines when holding shift in chat, along with support arrow up/down from the search input.

Will the change here cause a conflict with microsoft#1044 ?
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Aug 10, 2022
This extends the ability to intercept `keyDown` and `keyUp` events to `TextInput`.
We need this for the ability to insert newlines when holding shift in chat, along with support arrow up/down from the search input.

Will the change here cause a conflict with microsoft#1044 ?
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Aug 11, 2022
This extends the ability to intercept `keyDown` and `keyUp` events to `TextInput`.
We need this for the ability to insert newlines when holding shift in chat, along with support arrow up/down from the search input.

Will the change here cause a conflict with microsoft#1044 ?
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Aug 28, 2022
This extends the ability to intercept `keyDown` and `keyUp` events to `TextInput`.
We need this for the ability to insert newlines when holding shift in chat, along with support arrow up/down from the search input.

Will the change here cause a conflict with microsoft#1044 ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants